package com.work.dyduser.utils;

import android.util.Base64;

/**
 * @author WZ 2016/1/20
 *
 */
public class Base64Utils {
	// Base64加密算法
	public static String base64Encode(String str) throws Exception {
		byte[] retStr;
		if (StringUtils.isEmpty(str)) {
			return null;
		}
		try {
			// BASE64加密算法
			byte[] xmlStr = str.getBytes();
			retStr = Base64.encode(xmlStr, Base64.DEFAULT);
		} catch (Exception e) {
			throw new RuntimeException("Base64编码 加密 失败！");
		}
		String rStr = new String(retStr);
		return rStr;
	}

	// Base64解码算法
	public static String base64Decode(String str) throws Exception {
		if (StringUtils.isEmpty(str)) {
			return "";
		}
		byte[] bt = null;
		String retStr = "";
		try {
			bt = Base64.decode(str, Base64.DEFAULT);
			retStr = new String(bt);
		} catch (Exception e) {
			throw new RuntimeException("XML字符串Base64解码失败");
		}
		return retStr;
	}
}
